/**
 * 班级管理初始化
 */
var printWish = {
    id: "printWishTable",	//表格id
    seItem: null,		//选中的条目
    table: null,
    layerIndex: -1
};

/**
 * 初始化表格的列
 */
printWish.initColumn = function () {
    return [
        {title: 'id', field: 'id', visible: false, align: 'center', valign: 'middle'},
        {title: '准考证号', field: 'exam_card_number', visible: true, align: 'center', valign: 'middle'},
        {title: '姓名', field: 'student_name', visible: true, align: 'center', valign: 'middle'},
        {title: '所属学校', field: 'school_name', visible: true, align: 'center', valign: 'middle'},
        {title: '学校代码', field: 'school_code', visible: true, align: 'center', valign: 'middle'},
        {title: '所在班级', field: 'senoir_class_name', visible: true, align: 'center', valign: 'middle'},
        {title: '填报状态', field: 'write_status', visible: true, align: 'center', valign: 'middle'},
        {title: '确认状态', field: 'confirm_status', visible: true, align: 'center', valign: 'middle'}
    ];
};

/**
 * 检查是否选中
 */
printWish.check = function () {
    var selected = $('#' + this.id).bootstrapTable('getSelections');
    if (selected.length == 0) {
        Feng.info("请至少选中表格中的某一记录！");
        return false;
    } else {
        printWish.seItem = selected;
        return true;
    }
};

/**
 * 打印
 */
printWish.print = function () {
    if (this.check()) {
        var examineeIds = "";
        for (var i = 0; i < printWish.seItem.length; i++) {
            examineeIds += printWish.seItem[i].id + ",";
        }
        var ajax = new $ax(Feng.ctxPath + "/seniorWish/printWishPreview", function (data) {
            var index = layer.open({
                type: 1,
                title: '打印预览',
                area: ['93%', '93%'], //宽高
                fix: false, //不固定
                maxmin: true,
                content: data
            });
        }, function (data) {
            Feng.error("预览失败!" + data.responseJSON.message + "!");
        });
        ajax.set("examineeIds", examineeIds);
        ajax.setDataType("html");
        ajax.start();
    }
};

/**
 * 导出志愿信息表(学生信息)
 */
printWish.export = function () {
    var queryData = {};
    queryData['seniorSchoolId'] = $("#seniorSchoolId").val();
    queryData['seniorClassId'] = $("#seniorClassId").val();
    queryData['examCardNumber'] = $("#examCardNumber").val() ;
    queryData['confirmStatus'] = $("#confirmStatus").val();
    window.open(Feng.ctxPath +'/seniorExaminee/exportExaminee?'+$.param(queryData));
};


/**
 * 获取shoolId
 */
printWish.getSchoolId = function (schoolSelectId) {
    return {
        schoolId: $("#" + schoolSelectId).select2("val")
    }
}

$('#seniorSchoolId').on('select2:select', function (e) {
    $("#seniorClassId").val("").trigger("change");
});

printWish.resetSearch = function () {
    $("#seniorSchoolId").val("").trigger("change");
    $("#seniorClassId").val("").trigger("change");
    $("#examCardNumber").val("");
    $("#confirmStatus").val("").trigger("change");
    printWish.search();
}

/**
 * 查询班级列表
 */
printWish.search = function () {
    var queryData = {};
    queryData['seniorSchoolId'] = $("#seniorSchoolId").val();
    queryData['seniorClassId'] = $("#seniorClassId").val();
    queryData['examCardNumber'] = $("#examCardNumber").val();
    queryData['confirmStatus'] = $("#confirmStatus").val();
    printWish.table.refresh({query: queryData});
};

$(function () {
    var defaultColumns = printWish.initColumn();
    var table = new BSTable(printWish.id, "/seniorWish/printWishList", defaultColumns);
    table.setPageList([14,50,100,1000]);
    table.setMultiple(true);
    printWish.table = table.init();
});
